import { Button, Flex, Tooltip } from "antd";
import { FileDown } from 'lucide-react';
import { ChatItemProps } from "@ant-design/pro-chat";
import * as XLSX from 'xlsx';

function JsonToExcel(value: string){
    const workbook = XLSX.utils.book_new();
    const ws = XLSX.utils.json_to_sheet(JSON.parse(value));
    XLSX.utils.book_append_sheet(workbook, ws, 'Sheet1(RPA-Chat Create)');
    XLSX.writeFile(workbook, 'RPAChat_Data.xlsx');
}

export default function RPADownload(props: ChatItemProps<Record<string, any>>){
    return(
        <Flex gap="small" wrap>
            <Tooltip title="保存为Excel">
                <Button
                    icon={<FileDown />}
                    onClick={() => {
                        JsonToExcel(props?.originData?.content)
                    }}
                >
                </Button>
            </Tooltip>
        </Flex>
    );
}